home *** CD-ROM | disk | FTP | other *** search
/ Mac-Source 1994 July / Mac-Source_July_1994.iso / C and C++ / Libraries / SAT / myPlatform ƒ / myPlatform.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-09-21  |  2.8 KB  |  108 lines  |  [TEXT/KAHL]

  1. #include "SAT.h"
  2.  
  3. /**************/
  4. /* myPlatform demo*/
  5. /**************/
  6.  
  7. /* This demo is a hack I made, testing if we can use faceless sprites to make stationary*/
  8. /* obstacles. That worked pretty nicely, so I went on and made some moving platforms too.*/
  9. /* Take it for what it is: a test hack that suggests one way to make this kind of games.*/
  10. /* There are many other ways. The controls can be improved a lot, but it is a start.*/
  11.  
  12. /* Translated to C by Mike Zimmerman */
  13.  
  14. #include "myPlatform.h"
  15.  
  16. SATPatHandle    thepat;
  17. long             L;
  18. WindowPtr    gameWind;
  19. SpritePtr        ignoreSp;
  20. Point            p;
  21.  
  22. void DrawInfo()
  23. {
  24.     Rect    r;
  25.     
  26.     SetPort(backScreen);
  27.     SetRect(&r, 100, 50, 300, 100);
  28.     EraseRect(&r);
  29.     FrameRect(&r);
  30.     MoveTo(110, 70);
  31.     DrawString("\pSAT Platform demo");
  32.     MoveTo(110, 90);
  33.     DrawString("\pMove with , . and space");
  34.     SATBackChanged(r);
  35. }
  36.  
  37.  
  38. main()
  39. {
  40.     Rect        tempRect;
  41.  
  42.     MaxApplZone ();
  43.     FlushEvents (everyEvent - diskMask, 0 );
  44.     InitGraf (&thePort);
  45.     InitFonts ();
  46.     InitWindows ();
  47.     InitMenus ();
  48.     TEInit ();
  49.     InitDialogs (nil);        /* no restart proc */
  50.     InitCursor ();
  51.  
  52.     MoreMasters ();
  53.     MoreMasters ();
  54.  
  55.  
  56. /* End of initializations */
  57.  
  58.     ConfigureSAT(true, LayerSort, BackwardCollision, 32);
  59.     gameWind = InitSAT(0, 0, 512, 322);  /* No PICTs */
  60.  
  61.     /* Use a background pattern (instead of PICTs - just to demo that too) */
  62.     
  63.     SetPort(backScreen);  
  64.     thepat = SATGetPat(128);
  65.     SATPenPat(thepat);
  66.     SetRect(&tempRect, 0, 0, offSizeH, offSizeV);
  67.     PaintRect(&tempRect);
  68.     
  69.     CopyBits(&backScreen->portBits, &offScreen->portBits, &offScreen->portRect, &offScreen->portRect, srcCopy, nil);
  70.  
  71.     DrawInfo();
  72.     
  73. /*Initialize all sprite units*/
  74.     InitPlayerSprite();
  75.     InitPlatform();
  76.     InitMovPlatform();
  77.     InitHMovPlatform();
  78.     
  79. /*Show the game window and update it. (SATwind and gameWind are the same.)*/
  80.     ShowWindow(SATwind);
  81.     SelectWindow(SATwind);
  82.     PeekOffscreen();
  83.     
  84.     SetRect(&tempRect, 0, 0, offSizeH, offSizeV);
  85.       CopyBits(&(offScreen->portBits), &(SATwind->portBits), &tempRect, &tempRect, srcCopy, nil);
  86.  
  87.     GetMouse(&p);
  88.     ignoreSp = NewSprite(1, p.h, p.v, HandlePlayerSprite, SetupPlayerSprite, HitPlayerSprite);
  89.     ignoreSp = NewSprite(0, 50, 300, HandlePlatform, SetupPlatform, HitPlatform);
  90.     ignoreSp = NewSprite(0, 150, 200, HandlePlatform, SetupPlatform, HitPlatform);
  91.     ignoreSp = NewSprite(0, 250, 100, HandlePlatform, SetupPlatform, HitPlatform);
  92.     ignoreSp = NewSprite(0, 350, 50, HandlePlatform, SetupPlatform, HitPlatform);
  93.     ignoreSp = NewSprite(0, 350, 300, HandleMovPlatform, SetupMovPlatform, HitMovPlatform);
  94.     ignoreSp = NewSprite(0, 50, 200, HandleMovPlatform, SetupMovPlatform, HitMovPlatform);
  95.     ignoreSp = NewSprite(0, 200, 150, HandleHMovPlatform, SetupHMovPlatform, HitHMovPlatform);
  96.  
  97.     HideCursor();
  98.     while (!Button())
  99.     {
  100.         L = TickCount();
  101.         RunSAT(true);
  102.         while (L > TickCount() - 2L)
  103.             ;
  104.     }
  105.     ShowCursor();
  106.     SATSoundShutup();
  107. }
  108.